package pers.dawnyang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 
 * @author dawn yang
 * 
 */

@Configuration
@EnableSwagger2
// @Profile({ "local", "dev" })
@EnableSwaggerBootstrapUI
// @ConditionalOnProperty(prefix = "swagger", name = "open", havingValue = "true", matchIfMissing =
// true)
// http://localhost:8082/doc.html
// http://localhost:8082/swagger-ui.html
public class SwaggerConfig {

  private static final String BASE_PACKAGE = "pers.dawnyang.modular";

  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
        .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE)).paths(PathSelectors.any()).build();
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("使用Swagger2构建简单优雅的API文档").description("推荐RestFul风格")
        .termsOfServiceUrl("www.baidu.com").version("2.0").build();
  }
}
